package com.lidroid.xutils.sample.download;

import android.content.Context;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.http.HttpHandler;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;

/**
 * Created by antwei on 2015/8/23.
 */
public class LoadService {

    public static LoadService appService;
    private SubHttpUtils client;


    public static LoadService getInstance() {

        if (null == appService)
            appService = new LoadService();
        return appService;
    }

    private LoadService() {

        this.client = new SubHttpUtils();
    }



    private <T>HttpHandler<T> get(String url, RequestParams params, RequestCallBack<T> requestCallBack){
        return client.send(HttpRequest.HttpMethod.GET, url, params, requestCallBack);
    }

    private <T>HttpHandler<T> post(String url, RequestParams params, SubRequestCallBack<T> requestCallBack){
        return client.send(HttpRequest.HttpMethod.POST, url, params, requestCallBack);
    }

//    private <T>HttpHandler<T> download(String url, String targit, boolean autoResume, boolean autoRename){
//        return client.downl
//    }

    public void login(String username, String password, SubRequestCallBack<?> requestCallBack){
        RequestParams requestParams = new RequestParams();
        requestParams.addQueryStringParameter("username",username);
        requestParams.addQueryStringParameter("password",password);
        get("http://www.bes2.com/syl/syl/index.php/App/userLogin", requestParams, requestCallBack);
    }

    public void getDistribution(SubRequestCallBack<?> requestCallBack){
        get("http://www.bes2.com/syl/syl/index.php/App/getRecommendation",null, requestCallBack);
    }
}
